package cumt.wxl.winterolympics.filter;


import java.io.IOException;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebFilter({ "/jsp/introduction.jsp", "/jsp/statistics.jsp" , "/jsp/project.jsp"})
public class LoginFilter implements Filter {
    public void init(FilterConfig filterConfig) throws ServletException {

    }
    @Override
    public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws IOException, ServletException {
        HttpServletRequest request = (HttpServletRequest) req;
        HttpServletResponse  response = (HttpServletResponse) resp;
        Object user_session = request.getSession().getAttribute("user");
//        System.out.println(user_session);
        if (user_session != null){
            chain.doFilter(request,response);
        } else {
            response.sendRedirect("../index.jsp");
        }
    }

    public void destroy() {

    }
}

